Skip to content

runtime: implement weak.runtime_makeStrongFromWeak - #5633

Open
yohimik wants to merge 1 commit into
tinygo-org:devfrom
yohimik:upstream-pr/weak-strong-from-weak
Open

runtime: implement weak.runtime_makeStrongFromWeak#5633
yohimik wants to merge 1 commit into
tinygo-org:devfrom
yohimik:upstream-pr/weak-strong-from-weak

Conversation

@yohimik

@yohimik yohimik commented Aug 30, 2026

Copy link
Copy Markdown

runtime: implement weak.runtime_makeStrongFromWeak

What this does

The runtime has weak.runtime_registerWeakPointer but not its counterpart, so a
program that reads a weak pointer back does not link. The missing function is 7
lines.

Weak pointers are not weak here. registerWeakPointer returns the pointer that
it got, so the value it refers to stays and the way back to a strong pointer is
the identity too. weak.Pointer.Value thus never reports a collected value,
which the documented contract permits.

Evidence

testdata/weak.go makes a weak pointer and reads it back. It is registered in
TestBuild under the minor >= 24 gate, because the weak package came with
Go 1.24.

Measured on macOS 26.6 arm64.

Build Result
current dev link error, weak/pointer.go:89: linker could not find symbol _weak.runtime_makeStrongFromWeak
with this change weak value: 42

The program also builds for cortex-m-qemu, riscv-qemu and simavr.

A downstream product also ships binaries built with a fork that carries this
change, in the published release dispat v1.4.0.
https://github.com/yohimik/dispat/releases/tag/services%2Fdispat%2Fv1.4.0

Why it matters

crypto/tls uses weak.Pointer for its certificate cache, so this is a
prerequisite for the standard library crypto/tls on any target. Any user
program that uses weak hits the same link error today.

Scope

  • One new function in src/runtime/runtime.go. No API change, no behaviour
    change for a program that does not use weak.

Related pull requests

Each open PR in this series has a separate change. A dependency is not a copied commit.

In tinygo-org/net

Full Darwin networking also needs the merged net changes and a later src/net pin update. No upstream merge or current full-suite pass is implied by this list.

Additional independent gaps found in Crier are covered by #5655 (cookie-jar loader merge) and tinygo-org/net#82 (ListenConfig). They do not duplicate the process, TLS, deadline or server-TLS changes above. Current Crier comparison work is separate from its standard-Go release.

Current Crier evidence

The Crier report separates the original size comparison from a new CI-built candidate test. The original stripped Linux ARM64 result is 13,829,248 bytes versus Go's 30,277,794 bytes. Two render fixtures exceed pixel tolerance.

Candidate e7d34c8c126e0eecd2ce711915f2f88d112d833a, with net 0f460803, passed all 24 fork CI checks. Its downloaded compiler artifacts, with no source overlays, build unchanged Crier 7edaff9. Linux ARM64 E2E passed 143 cases with no failures or skips. Darwin ARM64 passed 142 with no failures and one platform trust-store skip. Darwin startup now works. A separate Darwin local-TLS matrix passes certificate rejection, plaintext refusal, update to a Go 1.1.0 target, and offline rollback. Both platforms pass spawn, signal, cookiejar, os/fcntl, and network probes.

These are combined-candidate results, not proof that this PR alone supplies all features. No new pixel or stripped-size comparison, amd64 execution, or current Dispat acceptance is claimed. WaitDelay and the recorded net limits remain open. No fork release was published.

The runtime had weak.runtime_registerWeakPointer but not its counterpart, so a
program that reads a weak pointer back did not link. crypto/tls does this in
the certificate cache that it keeps behind a weak.Pointer.

Weak pointers are not weak here. registerWeakPointer returns the pointer that
it got, so the value it refers to stays and the way back to a strong pointer is
the identity too. weak.Pointer.Value thus never reports a collected value,
which the documented contract permits.

testdata/weak.go does not link on the current dev branch and prints the
expected value with this change.
@yohimik
yohimik force-pushed the upstream-pr/weak-strong-from-weak branch from 1388449 to 931c476 Compare September 2, 2026 08:50
@yohimik

yohimik commented Sep 2, 2026

Copy link
Copy Markdown
Author

Rebased on dev after the 0.42.0 release. The change applies on top of v0.42.0
as released without a conflict, and the diff is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant